package com.liang.drug.service.impl;/*
 *@Author: ljy
 *@Date:2021/10/31 23:22
 *
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liang.drug.entity.Saleinfo;
import com.liang.drug.mapper.SaleinfoMapper;
import com.liang.drug.service.ISaleinfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 销售记录 service 实现类
 */
@Service
public class SaleinfoServiceImpl extends ServiceImpl<SaleinfoMapper, Saleinfo> implements ISaleinfoService {
    //@Autowired
    @Resource
    private SaleinfoMapper saleinfoMapper;

    /**
     * @param pageNum  第几页
     * @param pageSize 每页的数量
     * @param param    查询参数 药品名称
     * @return
     */
    @Override
    public IPage<Saleinfo> selectSaleinfoPage(int pageNum, int pageSize, String param) {
        QueryWrapper<Saleinfo> queryWrapper = new QueryWrapper<>();
        //工具类为mybatisPlus的工具类
        if (StringUtils.isNotEmpty(param)) {
            queryWrapper.like("dname", param);
        }
        Page<Saleinfo> page = new Page<>(pageNum, pageSize);
        return saleinfoMapper.selectPage(page, queryWrapper);
    }

    /**
     * 插入
     * @param saleinfo
     * @return
     */
    @Override
    public int addSaleinfo(Saleinfo saleinfo) {
        return saleinfoMapper.insert(saleinfo);
    }

    /**
     * 修改
     * @param saleinfo
     * @return
     */
    @Override
    public int editSaleinfo(Saleinfo saleinfo) {
        return saleinfoMapper.updateById(saleinfo);
    }

    /**
     * 根据主键id查询一个销售记录对象
     * @param id
     * @return
     */
    @Override
    public Saleinfo querySaleinfoById(Integer id) {
        return saleinfoMapper.selectById(id);
    }

    /**
     * 根据主键id删除一个销售记录对象
     * @param id
     * @return
     */
    @Override
    public int delSaleinfoById(Integer id) {
        return saleinfoMapper.deleteById(id);
    }


}
